<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>选择收货地址</title>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" />
<link rel="stylesheet" href="{{ url('/common/mobile-common/common.css') }}">	
<link rel="stylesheet" href="{{ url('mobile/css/member/address.css') }}">	
<script src="{{url('mobile/js/jquery-1.8.3.min.js')}}"></script>
<script src="{{ url('/common/mobile-common/hmt.js') }}"></script>
</head>
<body>
	<div class="abouts">
		<div class="wrap-cont clearfix">
				<!--选择收货地址-->
				<div class="wrap-cont address-choice">
					@forelse($list as $v)
					<div class="address-list" data-id="{{$v->id}}">
						<img class="dd-icn" src="{{ url('mobile/images/dd-icon.png')}}">
						<p class="fir-p">
							<span>{{ $v->name }}</span>
							<span>{{substr_replace($v->phone,"****",3,4)}}@if($v->sequence==1)<i>默认</i>@endif</span>
						</p>
						<p class="sec-p">
							<em>{{$v->province}}&nbsp{{$v->city}}&nbsp{{ $v->address }}</em>
							<input type="radio" @if($v->sequence==1)checked="checked"@endif name="mraddress">
							<img class="img" src="{{ url('mobile/images/no-check.png') }}"> 
						</p>
					</div>
					@empty
						<p class="no-address">没有收货地址</p>
					@endforelse
					<div class="opt-btn">
						<a class="gl-btn">管理</a>
					</div>
				</div>
				<!--end-->
		</div>
	</div>
</body>
<script>
	$(function(){
		//选择收货地址页面默认地址切换
		$(".address-list .sec-p input[type=radio]:checked").next().attr("src",'{{ url('mobile/images/check.png') }}');
		
		$(".address-list .sec-p input[type=radio]").unbind().click(function(e){
			$(".address-list .sec-p input[type=radio]").attr("checked",false);
			$(this).parent().find("input[name=mraddress]").attr("checked",true);
			$(".address-list .sec-p .img").attr("src",'{{ url('mobile/images/no-check.png') }}');
			$(this).next().attr("src",'{{ url('mobile/images/check.png') }}');
			
			$.ajax({
					type:'post',
					url:"{{ url('wap/receiver/confirm') }}",
					data:{receiver_id:receiver_id},
					success:function(data){
						if(data.success){
							window.location.href="{{url('wap/order/commit')}}";
						}
					}
				});
				
			e.stopPropagation(); 
		});

		$(".address-choice .gl-btn").click(function(){
			window.location.href="{{url('wap/receiver/index')}}";
		});
		//管理收货地址页面默认地址选择
		$(".address-list div input[type='radio']").click(function(e){
			var receiver_id = $(this).data('id');
			if(confirm("确认设为默认地址吗？")){
				var _this = $(this);
				$.ajax({
					type:'post',
					url:"{{ url('wap/receiver/setDefault') }}",
					data:{id:_this.data('id')},
					success:function(data) {
						if (data.success) {
							location.reload();
						}
					}
				});
			}		
		});
		//管理收货地址页面删除地址
		$(".del-address").click(function(){
			var confir=confirm("确定删除地址吗?");
			if(confir){
				var _this = $(this);
				$.ajax({
					type:'post',
					url:"{{ url('wap/receiver/delete') }}",
					data:{id:_this.data('id')},
					success:function(data){
						if(data.success){
							location.reload();
						}
					}
				});
			}
		});

		//点击触发单选框事件
		$(".address-list").click(function(t){
			$(".address-list .sec-p input[type=radio]").attr("checked",false);
			$(this).find("input[name=mraddress]").attr("checked",true);
			$(".address-list .sec-p .img").attr("src",'{{ url('mobile/images/no-check.png') }}');
			$(this).find(".img").attr("src",'{{ url('mobile/images/check.png') }}');
			t.stopPropagation(); 
			
			if ($(this).find('[name=mraddress]').attr("checked")) {
				var receiver_id = $(this).data('id');
				$.ajax({
					type:'post',
					url:"{{ url('wap/receiver/confirm') }}",
					data:{receiver_id:receiver_id},
					success:function(data){
						if(data.success){
							window.location.href="{{url('wap/order/commit')}}";
						}
					}
				});
			}
		})
	})
</script>
</html>
